Crate more_asserts[−][src]
Expand description
Small library providing some macros helpful for asserting. The API is very
similar to the API provided by the stdlib’s own assert_eq!
, assert_ne!
,
debug_assert_eq!
, or debug_assert_ne!
.
Name | Enabled | Equivalent to |
---|---|---|
assert_le! | Always | assert!(a <= b) |
assert_lt! | Always | assert!(a < b) |
assert_ge! | Always | assert!(a >= b) |
assert_gt! | Always | assert!(a > b) |
debug_assert_le! | if cfg!(debug_assertions) | debug_assert!(a <= b) |
debug_assert_lt! | if cfg!(debug_assertions) | debug_assert!(a < b) |
debug_assert_ge! | if cfg!(debug_assertions) | debug_assert!(a >= b) |
debug_assert_gt! | if cfg!(debug_assertions) | debug_assert!(a > b) |
debug_unreachable! | if cfg!(debug_assertions) | unreachable! when debug_assertions are on. |
When one of the assertions fails, it prints out a message like the following:
thread 'main' panicked at 'assertion failed: `left < right`
left: `4`,
right: `3`', src/main.rs:47:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Example
#[macro_use]
extern crate more_asserts;
#[derive(Debug, PartialEq, PartialOrd)]
enum Example { Foo, Bar }
fn main() {
assert_le!(3, 4);
assert_ge!(10, 10,
"You can pass a message too (just like `assert_eq!`)");
debug_assert_lt!(1.3, 4.5,
"Format syntax is supported ({}).", "also like `assert_eq!`");
assert_gt!(Example::Bar, Example::Foo,
"It works on anything that implements PartialOrd, PartialEq, and Debug!");
}
Macros
Panics if the first expression is not greater than or equal to the second.
Requires that the values be comparable with >=
.
Panics if the first expression is not strictly greater than the second.
Requires that the values be comparable with >
.
Panics if the first expression is not less than or equal to the second.
Requires that the values be comparable with <=
.
Panics if the first expression is not strictly less than the second.
Requires that the values be comparable with <
.
Same as assert_ge!
in debug builds or release builds where the
-C debug-assertions
was provided to the compiler. For all other builds,
vanishes without a trace.
Same as assert_gt!
in debug builds or release builds where the
-C debug-assertions
was provided to the compiler. For all other builds,
vanishes without a trace.
Same as assert_le!
in debug builds or release builds where the
-C debug-assertions
was provided to the compiler. For all other builds,
vanishes without a trace.
Same as assert_lt!
in debug builds or release builds where the
-C debug-assertions
was provided to the compiler. For all other builds,
vanishes without a trace.
Panics if reached. This is a variant of the standard library’s unreachable!
macro that is controlled by cfg!(debug_assertions)
.